class Resource::Query < ActiveRecord::Base
  set_table_name "resource_queries"

  has_many :collections
  has_many :tokens, :through => :collections

  def query_to_s
    token_array = Array.new
    collections = Resource::Collection.find(:all, :conditions => ["query_id = ?", self.id])
    collections.each { |c| token_array << c.token_id }
    tokens = Resource::Token.find(token_array)

    token_content_array = Array.new
    tokens.each { |t| token_content_array << t.content }
    return token_content_array.join(' ')
  end
end
